package com.gexin.model.order;

import com.gexin.common.utils.SQLUtils;
import com.gexin.common.utils.StringUtil;
import com.gexin.model.order.base.BaseOrderSum;
import com.gexin.model.shop.ShopInfo;
import com.jfinal.plugin.activerecord.Page;

import java.util.List;

/**
 * 业务名称:  t_order_sum()
 */
@SuppressWarnings("serial")
public class OrderSum extends BaseOrderSum<OrderSum> {
	public static final OrderSum dao = new OrderSum();


	public List<OrderSum> findByAll(){
		return find("select * from t_order_sum where date_type=1");
	}

	/**
	 * 后台的
	 * @param sum
	 * @param shop
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	public Page<OrderSum> paginate(OrderSum sum, ShopInfo shop, int pageNumber, int   pageSize){
		SQLUtils sql = new SQLUtils(" from t_order_sum as s left join t_shop_info as i on s.shop_id = i.shop_id where s.date_type=1  ");
		if(shop!=null){
			if(shop.getShopName()!=null){
				sql.whereLike(" i.shop_name", shop.getShopName());
			}
			if(StringUtil.isNotBlank(shop.getShopId())){
				sql.whereLike(" i.shop_id", shop.getShopId());
			}
		}

		sql.append(" order by s.date desc");
		return dao.paginate(pageNumber, pageSize, "select  s.*,i.*  ", sql.toString());
	}


	public Page<OrderSum> paginateShangjia(OrderSum sum, ShopInfo shop, String shop_id, int pageNumber, int   pageSize){
		SQLUtils sql = new SQLUtils(" from t_order_sum as s left join t_shop_info as i on s.shop_id = i.shop_id where s.date_type=1  ");
		if(shop_id!=null){
			sql.whereEquals("s.shop_id", shop_id);
		}

		if(shop!=null){
			if(shop.getShopName()!=null){
				sql.whereLike(" i.shop_name", shop.getShopName());
			}
		}

		sql.append(" order by s.date desc");
		return dao.paginate(pageNumber, pageSize, "select  s.*,i.*  ", sql.toString());
	}

	/**
	 * 实时最新数据
	 * @param shop_id
	 * @return
	 */
	public OrderSum getLatestData(String shop_id){
		return dao.findFirst("select * from t_order_sum where shop_id=? and date_type=2 order by date desc",shop_id);
	}
}
